package xyz.yang.toodles.statemachine;

/**
 * @author Xuehong Yang
 * @since 1.0
 */
public enum ContractState implements State {
    INIT("INIT", "草稿"),
    WAITING_FOR_APPROVED("WAITING_FOR_APPROVED", "待审批"),
    APPROVED("APPROVED", "已通过"),
    REJECTED("REJECTED", "已驳回"),
    CANCELLED("CANCELLED", "已取消");

    private final String name;
    private final String description;

    ContractState(String name, String description) {
        this.name = name;
        this.description = description;
    }

    public static ContractState getTargetState(ContractState sourceState, ContractEvent event) {
        return STATE_MACHINE.getTargetState(sourceState, event);
    }

    private static final StateMachine<ContractState, ContractEvent> STATE_MACHINE = new StateMachine<>();

    static {
        STATE_MACHINE.config(null, ContractEvent.CONTRACT_CREATE, INIT);
        STATE_MACHINE.config(INIT, ContractEvent.CONTRACT_SUBMIT, WAITING_FOR_APPROVED);
        STATE_MACHINE.config(INIT, ContractEvent.CONTRACT_CANCEL, CANCELLED);
        STATE_MACHINE.config(WAITING_FOR_APPROVED, ContractEvent.CONTRACT_APPROVE, APPROVED);
        STATE_MACHINE.config(WAITING_FOR_APPROVED, ContractEvent.CONTRACT_REJECT, REJECTED);
        STATE_MACHINE.config(REJECTED, ContractEvent.CONTRACT_SUBMIT, WAITING_FOR_APPROVED);
        STATE_MACHINE.config(REJECTED, ContractEvent.CONTRACT_CANCEL, CANCELLED);
    }


}
